﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using System.Data.SqlClient;


namespace DAO
{
    public class Nhanvien_DAO
    {

        SqlConnection cn = DataProvider.ConnectDB();

        public DataSet LichLamViec(int manv)
        {          
            DataSet ds = new DataSet();
            SqlCommand cmd = new SqlCommand("sp_LichLamViec", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@manv", manv));
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);

            cn.Close();
            return ds;
        }

        public int Huy_LichLamViec(Nhanvien_DTO nv, int mavc, int maxe)
        {         
            SqlCommand cmd = new SqlCommand("sp_HuyDangKy", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@manv", nv.Ma_nv));
            cmd.Parameters.Add(new SqlParameter("@mavc", mavc));
            cmd.Parameters.Add(new SqlParameter("@maxe", maxe));
            cmd.Parameters.Add(new SqlParameter("@vaitro", nv.Vaitro));
            SqlParameter output = cmd.Parameters.Add(new SqlParameter("@msg", SqlDbType.NVarChar, 150));
            output.Direction = ParameterDirection.Output;

            int i = cmd.ExecuteNonQuery();

            nv.Msg = output.Value.ToString();

            cn.Close();
            if ((i >= 0))
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
    }
}
